var AIConst = require('./AIConst');
var REST = require('./utils/RestHepler');
var AnalyzeStatus = require('../model/AIAnalyzeData').AnalyzeStatus;

class VloudDAO {
    constructor(vloud_api) {
        this._HttpApi = vloud_api;
    }

    _getFullUri(uri) {
        return this._HttpApi + uri;
    }

    requestToken(appkey, func) {
        REST.get(this._getFullUri(AIConst.TOKEN_URI + appkey)).then(func).catch((err)=>{
            console.error("requestToken error:" + err);
        });
    }

    subScribeNotify(notifyUri, _appkey, func) {
        let that = this;
        let param = {
            appkey:_appkey,
            observer:notifyUri
        };
        let uri = that._getFullUri(AIConst.SUBSCRIBE_NOTIFY);
        REST.put(uri, param).then(func);
    }

    play(analyze, token, appkey, func) {
        let that = this;
        let param = analyze.getPlayParam(token, appkey);
        let uri = that._getFullUri(AIConst.PLAY_URI);
        console.error(JSON.stringify(param));
        REST.put(uri, param).then(func);
    }

    analyze(analyze, appkey, func) {
        let that = this;
        let param = analyze.getStartAnalyzeParam(appkey);
        let uri = that._getFullUri(AIConst.ANALYZE_URI);
        REST.put(uri, param).then(func);
    }

    stopAnalyze(analyze, appkey, func) {
        let that = this;
        let param = analyze.getStopAnalyzeParam(appkey);
        let uri = that._getFullUri(AIConst.ANALYZE_URI);
        console.error(JSON.stringify(param));
        REST.delete(uri, param).then(func);
    }
    releaseRoom(analyze, token, appkey, func) {
        let param = analyze.getReleaseParam(token, appkey);
        let uri = that._getFullUri(AIConst.RELEASE_ROOM);
        REST.post(uri, param).then(func);
    }
}
module.exports = VloudDAO;
